package se.webbzon.boltzmann.object.factory;

import se.webbzon.boltzmann.environment.AbstractEnvironment;
import se.webbzon.boltzmann.environment.EnvironmentInflator;
import se.webbzon.oschi01.worldeditor.WorldObjectDeflation;
import se.webbzon.oschi01.worldobject.WorldObject;

public class InstanceFactoryInflator extends EnvironmentInflator {

	// All available instance factories for this instance factory inflator
	private final InstanceFactoryGroup factories;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public InstanceFactoryInflator(AbstractEnvironment env, InstanceFactoryGroup factories) {
		super(env,InstanceFactoryObject.worldObjectName);
		this.factories = factories;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public WorldObject makeWorldObject(WorldObjectDeflation deflation) {
		InstanceFactoryDeflation factoryDeflation = ((InstanceFactoryDeflation) deflation);
		WorldObject instance;
		try {
			instance = factoryDeflation.makeWorldObject(getEnvironment(),factories);
		} catch (InstanceFactoryException e) {
			instance = new InstanceFactoryObject();
		}
		return instance;
	}

	@Override public WorldObjectDeflation makeDeflation(int deflationProperties, WorldObject[] dependencies) {
		return new InstanceFactoryDeflation(deflationProperties);
	}

}
